﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DAO;
using DTO;

namespace Presentation
{
    public partial class UserControlHangCanNgay : UserControl
    {
        public UserControlHangCanNgay()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void btnKiemTra_Click(object sender, EventArgs e)
        {
            try
            {
                int n = int.Parse(txtSoNgayHetHang.Text);
                DuocPhamDao dpDao = new DuocPhamDao();
                DuocPhamDto[] dpDto = dpDao.SelectHangcanngay(n);

                dgvHangcanngay.AutoGenerateColumns = false;
                dgvHangcanngay.DataSource = dpDto;
                float sum = 0;
                for (int i = 0; i < dgvHangcanngay.Rows.Count; i++)
                {
                    sum = sum + float.Parse(dgvHangcanngay.Rows[i].Cells[5].Value.ToString());
                }
                txtTongtien.Text = Convert.ToDecimal(sum).ToString();
            }
            catch (Exception)
            {

                MessageBox.Show("Không có dữ liệu!");
            }
        }

        private void dgvHangcanngay_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            DataGridView grv = (DataGridView)sender;
            Utils.MakeSothutuColumn(grv, "itemStt");
        }

        private void btnLuuBaoCao_Click(object sender, EventArgs e)
        {
            Utils.ExportToExcel(dgvHangcanngay);
        }

        private void UserControlHangCanNgay_Load(object sender, EventArgs e)
        {

        }

        private void btnIn_Click(object sender, EventArgs e)
        {

        }
    }
}
